package a_exception.e_finally;

import a_exception.d_tryCatch.ArrayTest;
import a_exception.d_tryCatch.ClassCastTest;
import a_exception.d_tryCatch.NullPointerTest;

/*
    finally的使用
        try - finally
        try - catch - finally
 */
public class FinallyDemo {
    public static void main(String[] args) {
        try{
            ArrayTest.m1();
            NullPointerTest.m2();
            ClassCastTest.m3();
        }catch (ArrayIndexOutOfBoundsException e){
            //打印栈路径 e.printStackTrace();
            //可以做任意判断
            System.out.println("数组下标越界了");
            //获取异常信息
            String message = e.getMessage();
            System.out.println(message);
        }catch (NullPointerException e){
            System.out.println("空指针异常");
        }catch (ClassCastException e){
            System.out.println("类型转换异常");
        }catch (RuntimeException e){//抓取异常父类,可以抓取所有信息
            System.out.println("运行异常");
        }finally {
            System.out.println("程序一定会执行的内容");
        }
    }
}
